<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    // 创建一个对象
    var obj = { name: "张三", age: 20, weight: "80kg", habit: ["唱", "跳", "rap", "篮球"] }
    var obj2 = Array.isArray(obj) ? [] : {}
    function copyobj(obj) {
        for (var key in obj) {
            if (typeof obj[key] == 'object') {
                obj2[key] = copyobj(obj[key])
            } else {
                obj2[key] = obj[key]
            }
        }
        return obj2
    }
    var obj2 = copyobj(obj)
    console.log(obj2);
</script>